<?php


namespace addons\faqueue\library\jobs;


use app\common\exception\NException;
use app\common\library\helper\WxHelper;
use think\Log;
use think\queue\Job;

class TestJob
{

    /**
     * @throws NException
     */
    public function fire(Job $job, $data)
    {
        $accessToken = WxHelper::getAccessToken();
        $userList = WxHelper::userList($accessToken);
//        dump($userList);
//        $userList = [];
//        for ($i = 0; $i < 2000; $i++) {
//            $data['touser'] = 'oz5ky6ANfyjbjS4ExUL5eoz6wYHA';
//            WxHelper::sendNotice($data, $accessToken);
//            echo "{$i}_发送成功";
//        }
        foreach ($userList as $key => $value) {
            $data['touser'] = $value;
            WxHelper::sendNotice($data, $accessToken);
            echo "{$key}_发送成功";
        }
        //任务完成后需要删除 否则会重复执行
        $job->delete();
    }

    public function failed($data)
    {
        Log::write("任务执行失败：".print_r(['data' => $data,],true),'error');
    }
}